package org.dinnermate.gui;

import java.sql.SQLException;

import javax.swing.DefaultListModel;
import javax.swing.JList;

import net.java.ao.EntityManager;

import org.dinnermate.food.Ingredient;
import org.dinnermate.food.MenuItemIngredient;
import org.dinnermate.menu.MenuItem;

public class CreateIngredientLists
{
	public CreateIngredientLists(){
		
	}
	
	public static void generateLists(MenuItem currMenuItem, JList jList5, JList jList6, DefaultListModel jList5Model, DefaultListModel jList6Model, EntityManager em){
		MenuItemIngredient[] miis = currMenuItem.getIngredients();
		
		jList6Model = new DefaultListModel();
		
		for(int i = 0; i < miis.length; i++){
			jList6Model.addElement(miis[i]);
		}
		
		jList5Model = new DefaultListModel();
		
		Ingredient[] ingredients;
		try
		{
			ingredients = em.find(Ingredient.class);
			for(int i = 0; i < ingredients.length; i++){
				if(!TrackIngredients.duplicateIngredient(miis, ingredients[i])){
					jList5Model.addElement(ingredients[i]);
				}
			}
		}
		catch (SQLException e)
		{
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		jList5.setModel(jList5Model);
		jList6.setModel(jList6Model);
	}
}
